package net.kunyv.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class ColumnUtil
{
    public static final HashMap<String, String> mysql2mybatisMap = new HashMap<>();
    public static final HashMap<String, String> oracle2mybatisMap = new HashMap<>();
    public static final HashMap<String, String> mssql2mybatisMap = new HashMap<>();

    static  {
        mysql2mybatisMap.put("BIGINT", "BIGINT");
        mysql2mybatisMap.put("BIT", "BIT");
        mysql2mybatisMap.put("BLOB", "BLOB");
        mysql2mybatisMap.put("CHAR", "CHAR");
        mysql2mybatisMap.put("TEXT", "CLOB");
        mysql2mybatisMap.put("DATE", "DATE");
        mysql2mybatisMap.put("DECIMAL", "DECIMAL");
        mysql2mybatisMap.put("DOUBLE", "DOUBLE");
        mysql2mybatisMap.put("FLOAT", "FLOAT");
        mysql2mybatisMap.put("INTEGER", "INTEGER");
        mysql2mybatisMap.put("INT", "DECIMAL");
        mysql2mybatisMap.put("NUMERIC", "NUMERIC");
        mysql2mybatisMap.put("REAL", "REAL");
        mysql2mybatisMap.put("SMALLINT", "SMALLINT");
        mysql2mybatisMap.put("TIME", "TIME");
        mysql2mybatisMap.put("TIMESTAMP", "TIMESTAMP");
        mysql2mybatisMap.put("DATETIME", "TIMESTAMP");
        mysql2mybatisMap.put("TINYINT", "TINYINT");
        mysql2mybatisMap.put("VARCHAR", "VARCHAR");


        oracle2mybatisMap.put("BLOB", "BLOB");
        oracle2mybatisMap.put("CHAR", "CHAR");
        oracle2mybatisMap.put("CLOB", "CLOB");
        oracle2mybatisMap.put("DATE", "DATE");
        oracle2mybatisMap.put("DECIMAL", "DECIMAL");
        oracle2mybatisMap.put("NUMBER", "DECIMAL");
        oracle2mybatisMap.put("FLOAT", "FLOAT");
        oracle2mybatisMap.put("INTEGER", "INTEGER");
        oracle2mybatisMap.put("LONG VARCHAR", "LONGVARCHAR");
        oracle2mybatisMap.put("NCHAR", "NCHAR");
        oracle2mybatisMap.put("NCLOB", "NCLOB");
        oracle2mybatisMap.put("NUMERIC", "NUMERIC");
        oracle2mybatisMap.put("NUMBER", "NUMERIC");
        oracle2mybatisMap.put("REAL", "REAL");
        oracle2mybatisMap.put("SMALLINT", "SMALLINT");
        oracle2mybatisMap.put("TIMESTAMP", "TIMESTAMP");
        oracle2mybatisMap.put("VARCHAR", "VARCHAR");
        oracle2mybatisMap.put("VARCHAR2", "VARCHAR");



        mssql2mybatisMap.put("BIGINT", "BIGINT");
        mssql2mybatisMap.put("BIT", "BIT");
        mssql2mybatisMap.put("BLOB", "BLOB");
        mssql2mybatisMap.put("CHAR", "CHAR");
        mssql2mybatisMap.put("TEXT", "CLOB");
        mssql2mybatisMap.put("DATE", "DATE");
        mssql2mybatisMap.put("DECIMAL", "DECIMAL");
        mssql2mybatisMap.put("DOUBLE", "DOUBLE");
        mssql2mybatisMap.put("FLOAT", "FLOAT");
        mssql2mybatisMap.put("INTEGER", "INTEGER");
        mssql2mybatisMap.put("INT", "DECIMAL");
        mssql2mybatisMap.put("NUMERIC", "NUMERIC");
        mssql2mybatisMap.put("REAL", "REAL");
        mssql2mybatisMap.put("SMALLINT", "SMALLINT");
        mssql2mybatisMap.put("TIME", "TIME");
        mssql2mybatisMap.put("TIMESTAMP", "TIMESTAMP");
        mssql2mybatisMap.put("DATETIME", "TIMESTAMP");
        mssql2mybatisMap.put("TINYINT", "TINYINT");
        mssql2mybatisMap.put("VARCHAR", "VARCHAR");
    }











    public static String genClassAndMethodName(String str, boolean isTable, boolean isMybatis) {
        char[] ch = str.toCharArray();

        if (ch[0] >= 'a' && ch[0] <= 'z') {
            ch[0] = Character.toUpperCase(ch[0]);
        }
        for (int i = 1; i < ch.length; i++) {
            if (ch[i] >= 'A' && ch[i] <= 'Z') {
                ch[i] = Character.toLowerCase(ch[i]);
            }
            if (ch[i] == '_') {
                ch[i + 1] = Character.toUpperCase(ch[i + 1]);
                i++;
            }
        }
        int offset = 32;
        StringBuffer sb = new StringBuffer((new String(ch)).replace("_", ""));
        if (!isTable)
        {
            if (isMybatis) {

                if (ch[1] == '_') {
                    sb.setCharAt(0, Character.toLowerCase(ch[0]));

                }

            }
            else if (ch[1] == '_') {
                char abc = (char)(ch[0] + offset);
                sb.insert(1, abc);
            }
        }


        return sb.toString();
    }







    public static String genAtrributeName(String str, boolean isMybatis) {
        char[] ch = str.toCharArray();

        if (ch[0] >= 'A' && ch[0] <= 'Z') {
            ch[0] = Character.toLowerCase(ch[0]);
        }
        for (int i = 1; i < ch.length; i++) {
            if (ch[i] >= 'A' && ch[i] <= 'Z') {
                ch[i] = Character.toLowerCase(ch[i]);
            }
            if (ch[i] == '_') {
                ch[i + 1] = Character.toUpperCase(ch[i + 1]);
                i++;
            }
        }
        StringBuffer sb = new StringBuffer((new String(ch)).replace("_", ""));

        if (!isMybatis)
        {


            if (ch[1] == '_') {
                sb.insert(1, ch[0]);
            }
        }

        return sb.toString();
    }







    public static String sqlType2JavaType(String sqlType) {
        if (sqlType.equalsIgnoreCase("bit"))
            return "boolean";
        if (sqlType.equalsIgnoreCase("byte"))
            return "byte";
        if (sqlType.equalsIgnoreCase("smallint"))
            return "short";
        if (sqlType.equalsIgnoreCase("int"))
            return "int";
        if (sqlType.equalsIgnoreCase("bigint"))
            return "java.math.BigDecimal";
        if (sqlType.equalsIgnoreCase("float"))
            return "java.math.BigDecimal";
        if (sqlType.equalsIgnoreCase("decimal") || sqlType
                .equalsIgnoreCase("numeric") || sqlType
                .equalsIgnoreCase("real") || sqlType
                .equalsIgnoreCase("INTEGER") || sqlType
                .equalsIgnoreCase("number"))
            return "java.math.BigDecimal";
        if (sqlType.equalsIgnoreCase("money") || sqlType
                .equalsIgnoreCase("smallmoney"))
            return "java.math.BigDecimal";
        if (sqlType.equalsIgnoreCase("varchar2") || sqlType
                .equalsIgnoreCase("char") || sqlType
                .equalsIgnoreCase("nvarchar2") || sqlType.equalsIgnoreCase("varchar") || sqlType
                .equalsIgnoreCase("nchar") || sqlType.equalsIgnoreCase("clob"))
            return "java.lang.String";
        if (sqlType.equalsIgnoreCase("DATE") || sqlType
                .equalsIgnoreCase("datetime") || sqlType
                .equalsIgnoreCase("TIMESTAMP"))
            return "java.util.Date";
        if (sqlType.equalsIgnoreCase("image"))
            return "Blob";
        if (sqlType.equalsIgnoreCase("text")) {
            return "Clob";
        }
        return null;
    }







    public static String sqlType2sqlType4Mybatis(String sqlType, String databaseName) {
        if (databaseName.equals("ORACLE")) {
            return oracle2mybatisMap.get(sqlType.toUpperCase());
        }

        if (databaseName.equals("Sqlserver")) {
            return mssql2mybatisMap.get(sqlType.toUpperCase());
        }

        return mysql2mybatisMap.get(sqlType.toUpperCase());
    }


    public static String lowerCase(String str) {
        char[] ch = str.toCharArray();
        if (ch[0] >= 'A' && ch[0] <= 'Z') {
            ch[0] = (char)(ch[0] + 32);
        }
        return new String(ch);
    }


    public static void main(String[] args) {
        String s = "223,\t247.5,\t270,\t285.1,\t310.8,\t357.4,\t430.5,\t492.9,\t556.6,\t675,\t759.6,\t856.9,\t1023,\t1201.8,\t1371,\t1589.376,\t1820.352,\t2069.28,\t2352.864,\t2522.64";
        String[] sss = s.replaceAll(" ", "").split(",");
        List<Double> ddd = new ArrayList<>();
        for (String s1 : sss) {
            double b = Double.parseDouble(s1);
            ddd.add(Double.valueOf(b));
        }
        double total = ((Double)ddd.get(0)).doubleValue() * 1.08D;
        System.out.println(total);
        for (int i = 1; i < ddd.size(); i++) {
            total = (total + ((Double)ddd.get(i)).doubleValue()) * 1.08D;
            System.out.println(total);
        }
    }
}
